import { observable, action } from 'mobx';
import {WeaTableNew,WeaForm} from 'comsMobx'
const {TableStore} = WeaTableNew;
import * as Apis from '../apis/capital'
import {message} from "antd";
/**
 * @author ljc 2017-12-8
 * 项目列表通用store模板，适用于列表+高级搜索查询模式，实例：任务执行/
 */
export class ListStore{
    /** 列表store */
    @observable loading = false;
    title = "";
   @observable dataKey = "";
    @observable tableStore = new TableStore();

    /** 高级查询store */
    @observable form = new WeaForm();
    @observable showSearchAd = false;   //高级搜索显隐
     condition = [];

      /** 左侧树store */
	 @observable  leftTree = [];
	 @observable leftTreeCount = {};
	 @observable leftTreeCountType = [];
	 @observable selectedTreeKey = "";

    /** 顶部Tab组件store */
    topTab = [];
    topTabCount = {};

    constructor() {
        this.setLoading = this.setLoading.bind(this);
        this.setTitle = this.setTitle.bind(this);
        this.setShowSearchAd = this.setShowSearchAd.bind(this);
        this.setFormFields = this.setFormFields.bind(this);
        this.appendFormFields = this.appendFormFields.bind(this);
        this.clearFormFields = this.clearFormFields.bind(this);
        this.resetForm = this.resetForm.bind(this);
        this.resetTable = this.resetTable.bind(this);

    }
    //刷新列表
    @action
    reLoad = () => {
        this.tableStore.getDatas(this.tableStore.dataKey, this.tableStore.current, this.tableStore.pageSize, this.tableStore.sortParams)
    }

    @action
    setLoading(bool = false){
        this.loading = bool;
    }
    
    setTitle(title){
        this.title = title;
    }

    setShowSearchAd(bool) {
        this.showSearchAd = bool;
    }

    setFormFields(value){
        this.form.updateFields(value, true);    //true代表完全覆盖方式更新条件值
    }

    appendFormFields(value){
        this.form.updateFields(value, false);
    }

    clearFormFields(){
        this.form.resetConditionValue();      //清除查询条件值
    }

    resetForm(){
        this.form = new WeaForm();
    }

    resetTable(){
        this.dataKey = "";
        this.tableStore = new TableStore();
    }

     //删除
     onCptDel = (params={},type ="list",callBack) =>{
        Apis.doCptManager({viewtype:'cptdel',...params}).then(data => {
            if(data.success){
                if(data.msgid==='50'){
                    //校验删除资产资料，已存在资产或者待验收的，不能删除提示
                    message.warning(data.msg,3);
                }else{
                    message.success(data.msg);
                    if(type !== "card" ){
                        window._table.reLoad();
                        typeof callBack == "function" &&  callBack();
                    }else{
                        window.opener._table.reLoad(); 
                        window.opener._cptTable.reLoadTree();
                        window.close();
                        typeof callBack == "function" &&  callBack();
                    }
                }
            }else{
                message.error(data.msg);
            }
        }).catch(err => message.error(err))
     }
    

}